/**
 * Created by zhaolei on 15/5/4.
 */

'use strict';

var should = require('should');
var moment = require('moment');
var POP3 = require('../pop3');
var _ = require('lodash');
var async = require('async');

var sina_conf = {
  hostname: 'pop.sina.com',
  username: 'xxxxxxxxx@sina.com',
  password: 'xxxxxxxxx'
};

var offset = 10;
var limit = 0;

describe('POP3 sina Mail Test',function(){
  it('getContent Email',function(done){
    var pop3 = new POP3(sina_conf);
    var stop = false;

    async.whilst(function(){
      return !stop;
    },function(callback){
      pop3.getContent('2015-05-09',limit,offset,function(err,res){
        if(typeof res !== 'object' || _.size(res) === 0){
          stop = true;
        }
        console.log('res:',res.length);
        _.forEach(res,function(item){
          should.exist(item.subject);
          should.exist(item.date);
          should.exist(item.html);
        });
        limit += 10;
        callback(err);
      });
    },function(err){
      return done(err);
    });
  });
});
